package com.changpay.zywy.ui.activity.count
import com.changpay.zywy.R
import com.changpay.zywy.base.BaseActivity
import com.changpay.zywy.base.IView
import com.changpay.zywy.ext.showToast
import com.changpay.zywy.ext.sss
import com.changpay.zywy.http.RetrofitHelper
import com.changpay.zywy.utils.DateUtil
import kotlinx.android.synthetic.main.activity_month_trand_count.*
import kotlinx.android.synthetic.main.title_layout.*


class CountTrandMonthActivity : BaseActivity(), IView,CountTrandMonthTwoView.CountChartActionClose {
    override fun loadTrandMonthCharData(month: String?) {
        if (month != null) {
            loadDatas(month)
        }
    }

    override fun attachLayoutRes(): Int {
        return R.layout.activity_month_trand_count
    }

    override fun showLoading() {

    }

    override fun hideLoading() {

    }

    override fun showDefaultMsg(msg: String) {
        showToast(msg)
    }

    override fun showMsg(msg: String) {
        showToast(msg)
    }

    override fun showError(errorMsg: String) {
        showToast(errorMsg)
    }




    override fun initData() {


    }

    override fun initView() {
        tv_title.text = "月交易量"
        iv_back.setOnClickListener { finish() }
        count_chart_month_trand.setFragmentManager(supportFragmentManager)
        count_chart_month_trand.setListener(this)
    }

    override fun start() {

        val time = DateUtil.getYearMonth(System.currentTimeMillis())
        loadDatas(time)

    }

    private fun loadDatas(time: String) {
        val param = hashMapOf<String, String>()
        param["key"] = token
        param["month"] = time
        param["gc_id"] = intent.getStringExtra("gc_id")
        RetrofitHelper.service.get_total_trading_month(param).sss(this)
        {
            val amount = it.result.trading_amount
            val number = it.result.trading_num
            count_chart_month_trand.setData(amount.cloud,amount.lineCard,amount.bankCard,amount.quickPay,amount.scaveCode,
                number.cloud,number.lineCard,number.bankCard,number.quickPay,number.scaveCode)
        }
    }
}
